package br.com.viewcar.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

import org.hibernate.annotations.Type;

import com.vividsolutions.jts.geom.Polygon;

@Entity
@Table(name = "AREA", schema = "CHECKROTA")
@NamedQueries({
	@NamedQuery(name = "Area.findAll", query = "SELECT a FROM Area a WHERE a.status = 1"),
	@NamedQuery(name = "Area.findByArea", query = "SELECT a FROM Area a WHERE a.id = ?"),
	@NamedQuery(name = "Area.findByCliente", query = "SELECT a FROM Area a WHERE a.cliente.id = ? AND a.status = 1")
})
public class Area implements Serializable {

	private static final long serialVersionUID = -6489187041506857372L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name="ID", nullable = false)
	private Integer id;

	@Column(name="DESCRICAO", nullable = false, length = 50)
	private String nome;

	@Column(name="TIPO", nullable = false)
	private Integer tipo;

	@Column(name="STATUS", nullable = false)
	private Boolean status;

	@Column(name="GEOMAREA", nullable = false)
    @Type(type="org.hibernatespatial.GeometryUserType")
    private Polygon geometry;

	@ManyToOne
	@JoinColumn(name="CLIENTE_ID")
	private Cliente cliente;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public Boolean getStatus() {
		return status;
	}

	public void setStatus(Boolean status) {
		this.status = status;
	}

	public Integer getTipo() {
		return tipo;
	}

	public void setTipo(Integer tipo) {
		this.tipo = tipo;
	}

	public Polygon getGeometry() {
		return geometry;
	}

	public void setGeometry(Polygon geometry) {
		this.geometry = geometry;
	}

	public Cliente getCliente() {
		return cliente;
	}

	public void setCliente(Cliente cliente) {
		this.cliente = cliente;
	}

	public int hashCode() {

		int result = 1;
		result = 31 * result + ((id == null) ? 0 : id.hashCode());
		result = 31 * result + ((nome == null) ? 0 : nome.hashCode());
		result = 31 * result + ((tipo == null) ? 0 : tipo.hashCode());

		return result;
	}

	public boolean equals(Object obj) {

		if (this == obj)
			return true;

		if (obj == null)
			return false;

		if (getClass() != obj.getClass())
			return false;

		Area other = (Area) obj;

		return ((id == null && other.id == null) || (id != null && id.equals(other.id))) &&
			((nome == null && other.nome == null) || (nome != null && nome.equals(other.nome))) &&
			((tipo == null && other.tipo == null) || (tipo != null && tipo.equals(other.tipo)));
	}
}